package com.ruoyi.system.service.impl;

import com.ruoyi.common.core.domain.entity.RestaurantGoods;
import com.ruoyi.common.core.domain.entity.RestaurantGoodsDetail;
import com.ruoyi.system.mapper.ApproveMapper;
import com.ruoyi.system.mapper.ApproveMissionMapper;
import com.ruoyi.system.mapper.RestaurantGoodsDetailMapper;
import com.ruoyi.system.mapper.RestaurantGoodsMapper;
import com.ruoyi.system.service.RestaurantGoodsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author：liyouxin
 * @date：2023/8/15 18:42
 */
@Service
public class RestaurantGoodsServiceImpl implements RestaurantGoodsService {
	private static final Logger log = LoggerFactory.getLogger(RestaurantGoodsServiceImpl.class);

	@Resource
	private RestaurantGoodsMapper restaurantGoodsMapper;

	@Resource
	private RestaurantGoodsDetailMapper restaurantGoodsDetailMapper;

	@Resource
	private ApproveMapper approveMapper;

	@Resource
	private ApproveMissionMapper approveMissionMapper;

	@Override
	public List<RestaurantGoods> selectRestaurantGoodsList(RestaurantGoods restaurantGoods) {
		return restaurantGoodsMapper.selectRestaurantGoodsList(restaurantGoods);
	}

	@Override
	public List<RestaurantGoodsDetail> selectRestaurantGoodsDetailList(Long restaurantGoodsId) {
		RestaurantGoodsDetail query = RestaurantGoodsDetail.builder().goodsId(restaurantGoodsId).build();
		return restaurantGoodsDetailMapper.selectRestaurantGoodsDetailList(query);
	}

	@Override
	public Boolean createRestaurantGoodsDetail(RestaurantGoodsDetail restaurantGoodsDetail) {
		return restaurantGoodsDetailMapper.insertRestaurantGoodsDetail(restaurantGoodsDetail) == 1;
	}

	@Override
	public Boolean updateRestaurantGoodsDetail(RestaurantGoodsDetail restaurantGoodsDetail) {
		return restaurantGoodsDetailMapper.updateRestaurantGoodsDetail(restaurantGoodsDetail) == 1;
	}

	@Override
	public Boolean deleteRestaurantGoodsDetailById(Long id) {
		return restaurantGoodsDetailMapper.deleteRestaurantGoodsDetail(id) == 1;
	}

	@Override
	public RestaurantGoods selectRestaurantGoodsById(Long id) {
		return restaurantGoodsMapper.selectRestaurantGoodsById(id);
	}

	@Override
	public List<RestaurantGoods> selectByIds(List<Long> ids) {
		return restaurantGoodsMapper.selectByIds(ids);
	}

	@Override
	public RestaurantGoods selectById(Long id) {

			return restaurantGoodsMapper.selectById(id);
	}

	@Override
	public Boolean createRestaurantGoods(RestaurantGoods restaurantGoods) {
		return restaurantGoodsMapper.insertRestaurantGoods(restaurantGoods) == 1;
//		if (result != 1) {
//			log.warn("创建菜品 插入菜品失败 {}", JSON.toJSONString(restaurantGoods));
//			throw new ServiceException("创建菜品 插入菜品失败");
//		}
//		Long applicant = SecurityUtils.getUserId();
//		String creator = String.valueOf(SecurityUtils.getLoginUser().getUser().getPhonenumber());
//		ApproveMission approveMission = new ApproveMission();
//		approveMission.setActivityId(restaurantGoods.getId());
//		approveMission.setStatus(ApproveMissionStatus.WAITING.getCode());
//		approveMission.setCreateBy(creator);
//		approveMission.setActivityType("创建菜品");
//		approveMission.setApplicant(applicant);
//		result = approveMissionMapper.insertApproveMission(approveMission);
//		if (result != 1) {
//			log.warn("创建菜品 插入审核失败 {} {}", JSON.toJSONString(restaurantGoods), JSON.toJSONString(approveMission));
//			throw new ServiceException("创建菜品 插入审核失败");
//		}
//		Approve approve = new Approve();
//		approve.setApplicant(applicant);
//		approve.setApprover(1L);
//		approve.setActivityType("创建菜品");
//		approve.setActivityId(restaurantGoods.getId());
//		approve.setCreateBy(creator);
//		result = approveMapper.insertApprove(approve);
//		if (result != 1) {
//			log.warn("创建菜品 插入审核明细失败 {} {}", JSON.toJSONString(restaurantGoods), JSON.toJSONString(approve));
//			throw new ServiceException("创建菜品 插入审核明细失败");
//		}
//		return Boolean.TRUE;
	}

	@Override
	public Boolean updateRestaurantGoods(RestaurantGoods restaurantGoods) {
		return restaurantGoodsMapper.updateRestaurantGoods(restaurantGoods) == 1;
	}

	@Override
	public Boolean deleteRestaurantGoodsById(Long id) {
		return restaurantGoodsMapper.deleteRestaurantGoodsById(id) == 1;
	}


}
